# -*- coding: utf-8 -*-
import scrapy


class RenSpider(scrapy.Spider):
    name = 'ren'
    allowed_domains = ['www.renren.com']
    # start_urls = ['http://www.renren.com/']

    def start_requests(self):
        url = 'http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=201905199229'
        data = {
            'email': '547485239@qq.com',
            'icode': '',
            'origURL': 'http://www.renren.com/home',
            'domain': 'renren.com',
            'key_id': '1',
            'captcha_type': 'web_login',
            'password': '53f97b7c4a5c39d89a0c0fa478fde3e49a71e9758515f19d98d670e7fbd0233e',
            'rkey': 'a5165f71c59ebc8570923f0341cbc08a',
            'f': 'http%3A%2F%2Fwww.renren.com%2F335768579',
        }
        yield scrapy.FormRequest(
            url=url,
            formdata=data,
            callback=self.parse
        )

    def parse(self, response):
        # print(response)
        url = 'http://www.renren.com/335768579'
        yield scrapy.Request(url=url, callback=self.parse_title)

    def parse_title(self, response):
        title = response.selector.re_first('<title>(.*?)</title>')
        print(title)

